$package('jeecg.TostHrSocialsecurity');

butimport =function(callback){
	
	$('#import-win').dialog('open');
	$("#dd").datebox('getValue');
}
	
jeecg.TostHrSocialsecurity = function(){
	var _box = null;
	var _this = {
		toList:function(parentId){
				_box.form.search.resetForm();
				if(parentId){
					$('#search_parentId').val(parentId);
					$('#btnback').linkbutton('enable');
					_box.grid.datagrid('hideColumn','childMenus');
				}else{
					$('#btnback').linkbutton('disable');
					$('#btnback').linkbutton('disable');
					_box.grid.datagrid('showColumn','childMenus');
				}
				_box.handler.refresh();
		},
		//设置默认按钮数据
		addDefBtns:function(){
			var defaultBtns= [
				{"btnName":"添加","menuid":2,"actionUrls":"save.do","btnType":"add"},
				{"btnName":"修改","menuid":2,"actionUrls":"getId.do|save.do","btnType":"edit"},
				{"btnName":"删除","menuid":2,"actionUrls":"delete.do","btnType":"remove"}
				/*{"btnName":"导入","menuid":2,"actionUrls":"import.do","btnType":"import"}*/
			];
			var tbline = $(".tb-line:visible");
			var btnType = $("input[name='btnType']",tbline);
			$.each(defaultBtns,function(i,btn){
				var isExists = false;
				//判断按钮类型是否存在
				if(btnType.length > 0){
					for(var i =0; i < btnType.length; i++){
						if(btnType.eq(i).val() == btn.btnType){
							isExists = true;
							break;
						}
					}
				}
				if(!isExists){
					_this.addLine(btn);
				}
			});
		},
		addLine: function(data){
			var table = $("#btn-tb");
			var	html = "<tr class='tb-line'>";
			html+=	   "	<td align='center'><span  class='newFlag red'>*</span></td>";
			html+=	   "	<td><input name=\"btnName\" class=\"easyui-validatebox text-name\" style=\"width:100%\" data-options=\"required:true\"></td>";
			html+=	   "	<td><input name=\"btnType\" class=\"easyui-validatebox text-name\" style=\"width:100%\" data-options=\"required:true\"></td>";
			html+=	   "	<td><input name=\"actionUrls\" class=\"easyui-validatebox text-desc\" style=\"width:100%\"  ></td>";
			html+=	   "	<td align='center'><a class=\"easyui-linkbutton remove-btn\"  iconCls=\"icon-remove\" plain=\"true\"></a>";
			html+=	   "	<input class=\"hidden\" name=\"btnId\">";
			html+=	   "	<input class=\"hidden\" name=\"deleteFlag\">";
			html+=	   "	</td>";
			html+=	   "</tr>";
			var line = $(html);
			//版定删除按钮事件
			$(".remove-btn",line).click(function(){
				jeecg.confirm('Confirm','Are you sure you want to delete record?',function(r){
					if(r){
						_this.delLine(line);
					}
				})
			});
		/*	$(".import-btn",line).click(function(){
				jeecg.confirm('Confirm','Are you sure you want to import record?',function(p){
					if(r){
						_this.impLine(line);
					}
				})
			});*/
			if(data){
				if(data.id){
					$(".newFlag",line).html(''); //清空新增标记
				}
				$("input[name='btnId']",line).val(data.id);
				$("input[name='btnName']",line).val(data.btnName);
				$("input[name='btnType']",line).val(data.btnType);
				$("input[name='actionUrls']",line).val(data.actionUrls);
			}
			$.parser.parse(line);//解析esayui标签
			table.append(line);
			
		},
		//删除全部
		delAllLine:function(b){
			if(b){
				$(".tb-line").remove();
			}else{
				$(".tb-line").each(function(i,line){
					_this.delLine($(line));
				});
			}
		},
		//删除单行
		delLine:function(line){
			if(line){
				var btnId = $("input[name='btnId']",line).val();
				if(btnId){
					$("input[name='deleteFlag']",line).val(1); //设置删除状态
					line.fadeOut();
				}else{
					line.fadeOut("fast",function(){
						 $(this).remove();
					});
				}
			}
		},
		config:{
  			action:{
  				save:'', //新增&修改 保存Action  
  				getId:'',//编辑获取的Action
  				delele:''//删除数据的Action
  			},
  			event:{
  				add : function(){
  					_this.delAllLine(true);//清空已有的数据
  					_box.handler.add();//调用add方法
					var parentId =$('#search_parentId').val();
					if(parentId){
						$("#edit_parentId").val(parentId);
					}
				},
				edit:function(){
					_this.delAllLine(true);
					_box.handler.edit(function(result){
						if(result!=null && typeof(result.data.btns)!= "undefined"){
						$.each(result.data.btns,function(i,btn){
							_this.addLine(btn);
						});
						}
					});
				}
  			},
  			dataGrid:{
  				title:'社保表',
	   			url:'dataList.do',
	   			columns:[[
	   			    {field:'id',checkbox:true},
					//{field:'hrId',title:'基础信息ID',width:50,sortable:true},				
					{field:'hsoPercoding',title:'社保编码',width:80,sortable:true},				
					{field:'hsoName',title:'姓名',width:50,sortable:true},				
					{field:'hsoSalary',title:'缴费工资',width:60,sortable:true},				
					{field:'hsoPensionpay',title:'养老保险(单)',width:80,sortable:true},				
					{field:'hsoIndividpay',title:'养老保险(个)',width:80,sortable:true},
					{field:'hsoPsubtotal',title:'养老小计',width:80,sortable:true},
					{field:'hsoEn2month',title:'养老月数',width:60,sortable:true},
					
					{field:'hsoMedicalpay',title:'医疗单位缴纳',width:90,sortable:true},	
					{field:'hsoMedindividual',title:'医疗个人缴纳',width:90,sortable:true},	
					{field:'hsoMediillnes',title:'大病互助医疗',width:90,sortable:true},
					{field:'hsoMedicalbirth',title:'医疗生育',width:60,sortable:true},
					{field:'hsoMedicalsub',title:'医疗小计',width:60,sortable:true},	
					{field:'hsoMe2month',title:'医疗月数',width:60,sortable:true},				
								
					{field:'hsoUnitpay',title:'失业单位缴纳',width:90,sortable:true},				
					{field:'hsoIndpay',title:'失业个人缴纳',width:90,sortable:true},
					{field:'hsoUnemploysub',title:'失业小计',width:60,sortable:true},
					{field:'hsoUn2month',title:'失业月数',width:60,sortable:true},
					
					
					{field:'hsoInduinjury',title:'工伤保险',width:60,sortable:true},				
					{field:'hsoIn2month',title:'工伤月数',width:60,sortable:true},
					
					{field:'hsoSubtotalpay',title:'小计单位缴纳',width:60,sortable:true},
					{field:'hsoSubtotal',title:'小计个人缴纳',width:60,sortable:true},
					
					{field:'hsoTotal',title:'合计',width:60,sortable:true},				
					{field:'hsoMonth',title:'月份',width:60,sortable:true}				
				]],
				toolbar:[
							{id:'btnadd',text:'添加',btnType:'add'},
							{id:'btnedit',text:'修改',btnType:'edit'},
							{id:'btndelete',text:'删除',btnType:'remove'},
							{id:'btnimport',text:'批量导入',btnType:'tip',handler:butimport},
							{
								id:'btnback',
								text:'back',
								disabled: false,
								iconCls:'icon-back',
								handler:function(){
								history.back();
								}
							}
						]
					}
				},
				init:function(){
					_box = new YDataGrid(_this.config); 
					_box.init();
					$('#addLine_btn').click(_this.addLine);
					$('#addDefLine_btn').click(_this.addDefBtns);
					$('#delAllLine_btn').click(function(){
						jeecg.confirm('Confirm','Are you sure you want to delete record?',function(r){
							_this.delAllLine(false);
						});
					});
				}
			}
			return _this;
		}();

		//人员
		$("#hrName").combobox({
			url:urls['msUrl']+"tostHrBaseinfo/hrNameList.do",
			cache: false,  //tostHrDepartinfo/getDepartBypost  tostHrBaseinfo
		   // panelHeight: 'auto',//自动高度适合    去掉，显示滚动条
			dataType:'json',
			valueField:'id',
			textField:'hrName',
			multiple:false,
			formatter:function(result){
				 var s= "<span> <input type='hidden' class='selectId' style='vertical-align: middle' id='selectId_"+result.id+"' value='"+result.hrName+"'>"+result.hrName+"</span>";
				 return s;
			},
			onSelect:function(result){
				document.getElementById("hsoName").value=result.hrName;//把姓名的值赋给hsoName。
				$("#selectId_"+result.id).attr("checked", true);
			},
			onUnselect:function(result){
				$("#selectId_"+result.id).attr("checked", false);
			}
		});

		
$(function(){
	jeecg.TostHrSocialsecurity.init();
});		





